package com.snail.snailvr.utils;

import android.app.Activity;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.MenuRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.snail.snailvr.R;

/**
 * Toolbar util
 * Created by snail on 16/4/25.
 */
public class ToolbarUtil {
    public static void setupToolbar(final Activity context, Toolbar toolbar, @ColorRes int toolbarBg,@ColorRes int toolbarTitleBg, @DrawableRes int navigationIcon, String title, @MenuRes int menuResId){
        toolbar.setNavigationIcon(navigationIcon);
        TextView titleView=(TextView) toolbar.findViewById(R.id.toolbar_title);
        titleView.setText(title);
        titleView.setTextColor(ContextCompat.getColor(context, toolbarTitleBg));
//        toolbar.setTitle(title);
        toolbar.setBackgroundColor(ContextCompat.getColor(context, toolbarBg));
//        toolbar.setTitleTextColor(ContextCompat.getColor(context, toolbarTitleBg));
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.finish();
            }
        });
        titleView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.finish();
            }
        });
        if(menuResId!=-1)
            toolbar.inflateMenu(menuResId);

    }
}
